﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LabMS.Web.BaseData
{
    public partial class CourseList : Base.BasePage
    {
        ExtendBLL.CourseAndOther EClass = new ExtendBLL.CourseAndOther();
        protected void Page_Load(object sender, EventArgs e)
        {
            strPageUserType.Add("mana");
            strPagePrivilege.Add("KCSJ");

            if (!IsPostBack)
            {
                InitBind();
            }
        }

        protected void InitBind()
        {
            gvCourse.DataSource = EClass.GetModelList("1=1");
            gvCourse.DataBind();
        }

        /// <summary>
        /// 导出到EXCEL
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDel_Click(object sender, EventArgs e)
        {
            CheckBox chb;
            bool a = false;
            for (int i = 0; i < gvCourse.Rows.Count; i++)
            {
                chb = (CheckBox)gvCourse.Rows[i].FindControl("Chk");
                if (chb.Checked)
                {
                    int ID = int.Parse(gvCourse.DataKeys[i].Value.ToString());
                    try
                    {
                        EClass.Delete(ID);
                        a = true;
                    }
                    catch
                    {
                        Common.JShelper.JSAlert(this.Page, "", "该课程在课程大纲中存在，不能删除！");
                    }
                }
            }
            if (a == true)
            {
                Common.JShelper.JSAlert(this.Page, "", "删除成功！");
                InitBind();
            }
            else
            {
                Common.JShelper.JSAlert(this.Page, "", "删除失败！");
            }
        }

        protected void gvCourse_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvCourse.PageIndex = e.NewPageIndex;
            InitBind();
        }

        protected void gvCourse_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
                //e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");
                e.Row.Attributes["style"] = "Cursor:pointer";
            }
        }
    }
}
